package com.javaweb.admin.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javaweb.admin.entity.KdlInventoryDay;
import com.javaweb.admin.entity.NcTaskLog;
import com.javaweb.admin.entity.Scheduled;
import com.javaweb.admin.mapper.ScheduledMapper;
import com.javaweb.admin.service.AbstractJob;
import com.javaweb.admin.service.INcTaskLogService;
import com.javaweb.admin.service.KdlInventoryService;
import com.javaweb.common.utils.DateUtils;
import com.javaweb.common.utils.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class KdlInventoryTransferDataJob extends AbstractJob {
    private static final Logger log = LoggerFactory.getLogger(KdlInventoryTransferDataJob.class);
    @Autowired
    private ScheduledMapper scheduledMapper;
    @Autowired
    private KdlInventoryService kdlInventoryService;
    @Autowired
    INcTaskLogService iNcTaskLogService;
    @Override
    public String getName() {
        QueryWrapper<Scheduled> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("classpath",this.getClass().getName());
        Scheduled entity = scheduledMapper.selectOne(queryWrapper);
        return entity.getName();
    }

    @Override
    public void execute() {
        NcTaskLog taskLog = new NcTaskLog();
        taskLog.setTaskType("同步康德乐日库存数据");
        taskLog.setBillCount(0);
        taskLog.setStartTime(DateUtils.now());
        String billno = "";

        JsonResult result= kdlInventoryService.transferData();
        taskLog.setRemark(result.getMsg());
        taskLog.setBillNo(billno);
        taskLog.setEndTime(DateUtils.now());
        iNcTaskLogService.save(taskLog);

    }
}
